//
//  TicketExcahngeAndSigningController.m
//  NiuBanJin
//
//  Created by Billy on 15/10/15.
//  Copyright © 2015年 zzjr. All rights reserved.
//

#import "TicketExcahngeAndSigningController.h"
#import "ExchangeAndScoreHistoryController.h"
#import <CoreText/CTStringAttributes.h>
#import "ExchangeViewCell.h"
#import "Ticket.h"
#import "AllMemberTicketExchangeHistory.h"

@interface TicketExcahngeAndSigningController () <UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>

@property (nonatomic, strong) UIView *view_header ;// 顶部view
@property (nonatomic, strong) UIView *view_score;// 积分,兑换记录
@property (nonatomic ,strong) UITableView *tableView; //显示系统提供的加息券
@property (nonatomic, strong) NSArray *array_tickets; //加息券数据源

@property (nonatomic, strong) NSTimer *timer;
@property (nonatomic, strong) NSArray *array_allMemberExchangeList; //所有用户兑换的的记录
@property (nonatomic ,strong) UITableView *tableView_scrollShown; //滚动显示系统的加息券
@property (nonatomic, assign) int page;
@end

@implementation TicketExcahngeAndSigningController

#pragma mark - life cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self pageSettingsAndSubviewsCreation];
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    [self dataPreprationForCurrentpage];
}

- (void) viewDidAppear:(BOOL)animated {
    
    [super viewDidAppear:animated];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backgroundNotification:) name:UIApplicationDidEnterBackgroundNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgroundNotification:) name:
     UIApplicationWillEnterForegroundNotification object:nil];
}

- (void) viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    
    [self.timer invalidate];
}

#pragma mark - SubviewsCreationAndPageSettings

- (void) pageSettingsAndSubviewsCreation {
    
    [self.view setBackgroundColor:BASECOLOR];
    [self.navigationItem setTitle:[self.type isEqualToString:@"ticket"] ? @"兑换" :@"签到" ];
    
    [self setRightBarButtonItem];

    // add subviews
    [self.view addSubview:self.view_header];
    [self.view addSubview:self.view_score];
    [self.view addSubview:self.tableView_scrollShown];
    [self.view addSubview:self.tableView];
}

#pragma mark - TableView datasource && delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (tableView == self.tableView) {
        return [self.array_tickets count];
    }
    
    return [self.array_allMemberExchangeList count];
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (tableView == self.tableView_scrollShown) {
        
        static NSString *identiferShow = @"ExchangeViewCellShow" ;
        
        UITableViewCell *cell_show = [tableView dequeueReusableCellWithIdentifier:identiferShow];
        
        if (!cell_show) {
        
            cell_show = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identiferShow];
        }
        
        [cell_show setBackgroundColor:BASECOLOR];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, MULTIPLYHEIGHT(10.0), SCREEN_WIDTH, MULTIPLYHEIGHT(20.0))];
        [label setTextAlignment:NSTextAlignmentCenter];
        [label setTextColor:[UsefulUtil colorWithHexString:@"#434343"]];
        [label setTag:11];
        [label setFont:[UIFont systemFontOfSize:12.0]];
        
        [label setText:[self.array_allMemberExchangeList[indexPath.row] valueForKey:@"allMemberTicketExchangeHistory_exchangeNote"]];
        [cell_show.contentView addSubview:label];
         
        return cell_show;
    } else  {
        
        [tableView setRowHeight:MULTIPLYHEIGHT(180.0/2)];
        
        static NSString *identifer = @"ExchangeViewCell" ;
        
        ExchangeViewCell *cell = (ExchangeViewCell *)[tableView dequeueReusableCellWithIdentifier:identifer];
        
        if (!cell) {
            
            cell = [[ExchangeViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifer];
        }
        
        Ticket *tmp = [self.array_tickets objectAtIndex:indexPath.row];
        
        cell.ticket = tmp;
        
        return  cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    
    if (tableView == self.tableView_scrollShown) {
        
        return;
    }
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    Ticket *tmp = self.array_tickets [indexPath.row];
    
    NSString *ticket_score = tmp.ticket_exchangeScore;
    
    if ( [ticket_score integerValue]  > [[UserManager sharedUserManager].user.user_userScores integerValue] ) {  //用户的积分 小于 要求的积分，提示错误
        
        UIAlertView *alert_score = [[UIAlertView alloc] initWithTitle:@"积分不足!" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"如何获得积分?", nil];
        
        [alert_score show];
        return;
    }
    
    NSDictionary *dic_params = @{@"token":[UserManager sharedUserManager].user.user_userToken,@"userId":[UserManager sharedUserManager].user.user_userId,@"id":tmp.ticket_number_id};
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [[NetworkUtil sharedNetworkUtil] zzjrUseExchangeTicketByParmeteres:dic_params transferResultUsingBlock:^(id parsedData, NSError *error) {
        
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        if (!error) {
            
            NSDictionary *dic_result = parsedData;
            if (![dic_result count] == 0) { //保证返回来的有数据
                
                if ([dic_result[@"status"] integerValue] == 0) {
                    
                    if (dic_result[@"result"][@"score"]){ //能取到的情况下
                        
                        NSString *current_score = [NSString stringWithFormat:@"%@",dic_result[@"result"][@"score"]];
                        // 保存用户的本地记录
                        
                        User *user_tmp = [[UserManager sharedUserManager] getCurrentUser];
                        
                        [user_tmp setUser_userScores:current_score];
                        
                        [[UserManager sharedUserManager] saveCurrentUser:user_tmp];
 
                        UILabel *tmp = (UILabel*)[self.view_header viewWithTag:20];
                        
                        NSString *content = [NSString stringWithFormat:@"%@分",current_score];
                        
                        NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:content];
                        
                        [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18.0] range:NSMakeRange(content.length - 1, 1)];
                        
                        [tmp setAttributedText:attrStr]; //这儿server有BUG
                        
                            [UsefulUtil showAlertView:dic_result[@"result"][@"content"]];
                    }
                } else  {
                    
                    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
                    [UsefulUtil showAlertView:dic_result[@"msg"]];
                }
            }
        }else {
            
            [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
            [UsefulUtil showAlertView:error.description];
        }
    }];
}

#pragma mark - scrollview delegate

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
    
    [self.timer invalidate];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

    self.timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(contentOfLabelChange:) userInfo:nil repeats:YES];
}

#pragma mark - alert view delegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    switch (buttonIndex) {
        case 0:

            break;
            
        default:
        {
            
            [UsefulUtil showAlertView:@"这儿跳积分获取方法网页"];
        }
            break;
    }
}

#pragma mark - data source prepation

- (void) dataPreprationForCurrentpage {
    
    //因为server接口分开了，所以这儿得分三个接口来做
    
    //1. 获取加息券可兑换列表 ,系统提供了哪些可以换的奖品
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [self getExchangeList];
    });
    
    //2. 获取哪些用户兑换了加息券
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [self getExchangeHistoryList];
    });

}

- (void) getExchangeHistoryList {

    NSDictionary *dic_params = @{@"offSet":@"1"};
    
    [[NetworkUtil sharedNetworkUtil] zzjrGetTicketExchangeHistoryByParmeteres:dic_params transferResultUsingBlock:^(id parsedData, NSError *error) {
        
        if (!error) {  //没有网络错误
        
            if ([parsedData count] >0 ) {
                
                self.array_allMemberExchangeList = parsedData;
                
                [self.tableView_scrollShown reloadData];
                
                self.timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(contentOfLabelChange:) userInfo:nil repeats:YES];
            }else {
                // 没有获取 到用户数据 ，就不能做滚动动画了，直接显示为一个
            }
            
        }else {
            
            [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
            [UsefulUtil showAlertView:error.description];
        }
    }];
}

- (void) getExchangeList {
    
    NSDictionary *dic = [NSDictionary dictionary];
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [[NetworkUtil sharedNetworkUtil] zzjrGetExchangeTicketListByParmeteres:dic transferResultUsingBlock:^(id parsedData, NSError *error) {
        
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        
        if (!error) {  //没有网络错误
            
            // 开始解析数据
            NSMutableArray *mutableArray_serverData = parsedData;
            
            if ([mutableArray_serverData count] > 0) {
                
                self.array_tickets = mutableArray_serverData;
                
                [self.tableView reloadData];
                
            }else  { //数据返回为空
                
                
            }
            
        }else {
            
            [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
            [UsefulUtil showAlertView:error.description];
        }
    }];
}

#pragma mark - notification handling

- (void) backgroundNotification:(NSNotification *) nf {

    [self.timer invalidate]; //防止系统用snapshot 显示重影
    NSLog(@"进入后台");
}

- (void) forgroundNotification:(NSNotification *) nf {
    
    NSLog(@"进入前台");
    self.timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(contentOfLabelChange:) userInfo:nil repeats:YES];
}

#pragma mark - setter methods

- (UIView *)view_header {
    
    if (!_view_header) {
        
        _view_header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, MULTIPLYHEIGHT(220.0/2))];
        [_view_header.layer setContents:(__bridge id)([UIImage imageNamed:@"viewTop"].CGImage)];
        
        // 牛像
        CALayer *layer_cow = [UsefulUtil layerCreationWithFrame:CGRectMake(MULTIPLYWIDTH(26.0/2), MULTIPLYHEIGHT(30.0/2),MULTIPLYWIDTH(157.0/2), MULTIPLYHEIGHT(157.0/2)) andContents:(__bridge id)[UIImage imageNamed:@"cow"].CGImage];
        [_view_header.layer addSublayer:layer_cow];

        // 积分显示

        UILabel *label_scorePrompt = [UsefulUtil labelCreationWithFrame:CGRectMake(MULTIPLYWIDTH(242.0/2), MULTIPLYHEIGHT(54.0/2), MULTIPLYWIDTH(150.0/2), MULTIPLYHEIGHT(40.0/2)) textColor:[UIColor whiteColor] fontName:[UIFont systemFontOfSize:18.0] text:@"我的积分:"];
        [_view_header addSubview:label_scorePrompt];
        
        UILabel *label_score = [UsefulUtil labelCreationWithFrame:CGRectMake(CGRectGetMaxX(label_scorePrompt.frame), MULTIPLYHEIGHT(18.0/2), MULTIPLYWIDTH(260.0/2), MULTIPLYHEIGHT(60.0/2)) textColor:[UIColor whiteColor] fontName:[UIFont systemFontOfSize:40.0] text:@"100分"];
        //分字大小是36px
        
        NSString *score = [NSString stringWithFormat:@"%@",[UserManager sharedUserManager].user.user_userScores];
        
        if (score) {
            
            [label_score setText:[NSString stringWithFormat:@"%@分",score]];
        }
        
        NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:label_score.text];
        
        [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18.0] range:NSMakeRange(label_score.text.length - 1, 1)];
        [attrStr addAttribute:NSVerticalGlyphFormAttributeName value:@"1" range:NSMakeRange(label_score.text.length - 1, 1)];
        
        [label_score setAttributedText:attrStr];
        
        [label_score setTag:20];
        
        [label_score sizeToFit];
        [_view_header addSubview:label_score];
        
        if ([self.type isEqualToString:@"ticket"]) {
            
            [UIView animateWithDuration:0.1 animations:^{
                
                CGRect frame_old = label_scorePrompt.frame;
                
                frame_old.origin.y += MULTIPLYHEIGHT(40.0/2);
                [label_scorePrompt setFrame:frame_old];
            }];
            
            [UIView animateWithDuration:0.1 animations:^{
                
                CGRect frame_old = label_score.frame;
                
                frame_old.origin.y += MULTIPLYHEIGHT(40.0/2);
                [label_score setFrame:frame_old];
            }];
        }
        
        // 加上签到 和获得积分的，标识
        
        if ([self.type isEqualToString:@"sign"]) {
            
            UILabel *label_sign = [UsefulUtil labelCreationWithFrame:CGRectMake(label_scorePrompt.frame.origin.x, CGRectGetMaxY(label_scorePrompt.frame) + MULTIPLYHEIGHT(10.0/2), MULTIPLYWIDTH(100.0/2), MULTIPLYHEIGHT(30.0/2)) textColor:[UIColor whiteColor] fontName:[UIFont systemFontOfSize:11.0] text:@"今日已签到"];
            [_view_header addSubview:label_sign];
            
            UILabel *label_sign_score = [UsefulUtil labelCreationWithFrame:CGRectMake(MULTIPLYWIDTH(236.0/2), CGRectGetMaxY(label_sign.frame) + MULTIPLYHEIGHT(15.0/2), MULTIPLYWIDTH(180.0/2), MULTIPLYHEIGHT(40.0/2)) textColor:[UIColor whiteColor] fontName:[UIFont systemFontOfSize:11.0] text:[NSString stringWithFormat:@"获得积分 +%@",self.str_signScore ]];

            [label_sign_score.layer setCornerRadius:10.0];
            [label_sign_score.layer setBorderColor:[UIColor whiteColor].CGColor];
            [label_sign_score.layer setBorderWidth:1.0/2];
            [label_sign_score setTextAlignment:NSTextAlignmentCenter];
            
            [_view_header addSubview:label_sign_score];
        }
    }
    
    return _view_header;
}

- (UIView *)view_score {
    
    if (!_view_score) {
        
        _view_score  = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.view_header.frame), SCREEN_WIDTH, MULTIPLYHEIGHT(160.0/2))];
        [_view_score setBackgroundColor:[UIColor whiteColor]];
        
        // 积分记录
        
        UIImageView *imageView_score = [[UIImageView alloc] initWithFrame:CGRectMake(MULTIPLYWIDTH(72.0/2), MULTIPLYHEIGHT(35.0/2), MULTIPLYWIDTH(91.0/2), MULTIPLYHEIGHT(91.0/2))];
        [imageView_score setImage:[UIImage imageNamed:@"scoreHistory"]];
        [_view_score addSubview:imageView_score];
        [imageView_score setTag:10];
        UITapGestureRecognizer *tap_imageView_score = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesturehandling:)];
        [imageView_score setUserInteractionEnabled:YES];
        [imageView_score addGestureRecognizer:tap_imageView_score];
        
        UIButton *button_score = [UsefulUtil buttonCreationWithFrame:CGRectMake(CGRectGetMaxX(imageView_score.frame) + MULTIPLYWIDTH(20.0/2), MULTIPLYHEIGHT(68.0/2), MULTIPLYWIDTH(140.0/2), MULTIPLYHEIGHT(40.0/2)) textColor:[UsefulUtil colorWithHexString:@"#434343"] fontName:[UIFont systemFontOfSize:15.0] text:@"积分记录"];

        [button_score setTag:30];
        [button_score addTarget:self action:@selector(buttClickedAtChangePage:) forControlEvents:UIControlEventTouchUpInside];
        [_view_score addSubview:button_score];
        
        UIView *view_seperator = [[UIView alloc] initWithFrame:CGRectMake(MULTIPLYWIDTH(372.0/2), 0, 1.0, MULTIPLYHEIGHT(160.0/2))];
        [view_seperator setBackgroundColor:[UsefulUtil colorWithHexString:@"#EBEBEB"]];
        [_view_score addSubview:view_seperator];
        
        //兑换记录
        
        UIImageView *imageView_exchange = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view_seperator.frame) + MULTIPLYWIDTH(72.0/2), MULTIPLYHEIGHT(35.0/2), MULTIPLYWIDTH(91.0/2), MULTIPLYHEIGHT(91.0/2))];
        
        [imageView_exchange setImage:[UIImage imageNamed:@"changeHistory"]];
        [_view_score addSubview:imageView_exchange];

        [imageView_exchange setTag:11];
        
        UITapGestureRecognizer *tap_imageView_exchange = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesturehandling:)];
        [imageView_exchange setUserInteractionEnabled:YES];
        [imageView_exchange addGestureRecognizer:tap_imageView_exchange];
        
        
        UIButton *button_exchange = [UsefulUtil buttonCreationWithFrame:CGRectMake(CGRectGetMaxX(imageView_exchange.frame) + MULTIPLYWIDTH(20.0/2), MULTIPLYHEIGHT(68.0/2), MULTIPLYWIDTH(140.0/2), MULTIPLYHEIGHT(40.0/2)) textColor:[UsefulUtil colorWithHexString:@"#434343"] fontName:[UIFont systemFontOfSize:15.0] text:@"兑换记录"];

        [button_exchange setTag:31];
        [button_exchange addTarget:self action:@selector(buttClickedAtChangePage:) forControlEvents:UIControlEventTouchUpInside];
        [_view_score addSubview:button_exchange];
    }
    
    return  _view_score;
}


- (UITableView *)tableView {
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.tableView_scrollShown.frame), SCREEN_WIDTH, SCREEN_HEIGHT - CGRectGetMaxY(self.tableView_scrollShown.frame)) style:UITableViewStylePlain];
        [_tableView setDelegate:self];
        [_tableView setDataSource:self];
        [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        
        [_tableView setBackgroundColor:BASECOLOR];
        [_tableView setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
    }
    
    return  _tableView;
}

- (UITableView *)tableView_scrollShown {
    
    if (!_tableView_scrollShown) {
        
        _tableView_scrollShown = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.view_score.frame), SCREEN_WIDTH, MULTIPLYHEIGHT(62.0/2)) style:UITableViewStylePlain];
        [_tableView_scrollShown setDelegate:self];
        [_tableView_scrollShown setDataSource:self];
        [_tableView_scrollShown setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        [_tableView_scrollShown setBackgroundColor:BASECOLOR];
        [_tableView_scrollShown setAllowsSelection:NO];
        [_tableView_scrollShown setScrollEnabled:NO];
    }
    
    return _tableView_scrollShown;
}

- (void) setRightBarButtonItem {
    
    //兑换加息券
    
    UIButton *button_rightItem = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, MULTIPLYWIDTH(160.0/2), MULTIPLYHEIGHT(44.0))];
    [button_rightItem setTitle:@"签到规则" forState:UIControlStateNormal];
    [button_rightItem setTitleColor:[UsefulUtil colorWithHexString:@"#fb4747"] forState:UIControlStateNormal];
    [button_rightItem.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
    [button_rightItem addTarget:self action:@selector(signingRuleShown) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barItemRight = [[UIBarButtonItem alloc] initWithCustomView:button_rightItem];
    
    CALayer *layer_icon = [CALayer layer];
    
    [layer_icon setFrame:CGRectMake(0,MULTIPLYHEIGHT(15.0), MULTIPLYWIDTH(20.0/2), MULTIPLYHEIGHT(28.0/2))];
    [layer_icon setContents:(__bridge id)[UIImage imageNamed:@"navIcon"].CGImage];
    [button_rightItem.layer addSublayer:layer_icon];
    [button_rightItem.titleLabel setTextAlignment:NSTextAlignmentRight];
    [button_rightItem setTitleEdgeInsets:UIEdgeInsetsMake(0, 13.0, 0, 0)];
    [button_rightItem.titleLabel setAdjustsFontSizeToFitWidth:YES];
    
    [self.navigationItem setRightBarButtonItem:[self.type isEqualToString:@"ticket"] ? nil:barItemRight];
}

// 滑动手势, 父vc实现
- (void) swiperGestureHandle:(UISwipeGestureRecognizer *) swipe {
    
    //disable swiping
    
}

#pragma mark - button events handing 

- (void) buttClickedAtChangePage:(UIButton *) button {
    
    switch (button.tag) {
        case 31: //兑换
        {
            NSLog(@"exchange");
            ExchangeAndScoreHistoryController *shareVC = [[ExchangeAndScoreHistoryController alloc] init];
            [shareVC setType:@"exchangeHistory"];
            
            [self.navigationController pushViewController:shareVC animated:YES];
        }
            break;
        case 30: //积分
        {
            NSLog(@"score");
            ExchangeAndScoreHistoryController *shareVC = [[ExchangeAndScoreHistoryController alloc] init];
            [shareVC setType:@"scoreHistory"];
            
            [self.navigationController pushViewController:shareVC animated:YES];
        }
            break;
        default:
            break;
    }
}

- (void) contentOfLabelChange:(NSTimer *) timer { //滚动显示
    
    NSIndexPath *indexpath = [NSIndexPath indexPathForRow:0 inSection:0];

    UITableViewCell *cell = [self.tableView_scrollShown cellForRowAtIndexPath:indexpath];
   
    [cell.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    //  加新的label

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, MULTIPLYHEIGHT(10.0), SCREEN_WIDTH, MULTIPLYHEIGHT(20.0))];
    [label setTextAlignment:NSTextAlignmentCenter];
    [label setTextColor:[UsefulUtil colorWithHexString:@"#434343"]];
    [label setTag:11];
    [label setFont:[UIFont systemFontOfSize:12.0]];
    
    NSInteger index =  arc4random()%self.array_allMemberExchangeList.count;
    
    [label setText:[self.array_allMemberExchangeList[index] valueForKey:@"allMemberTicketExchangeHistory_exchangeNote"]];

    [cell addSubview:label];
    // 动画
    
    [self.tableView_scrollShown reloadRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationTop];

//    
//    UILabel *label = [cell.contentView viewWithTag:11];
//    
//    CGRect frame = label.frame;
//    
//    frame.origin.y = frame.origin.y - 10;
//    
//    [UIView animateWithDuration:1 animations:^{
//        
//        [label setFrame:frame];
//        
//    }];
//    
//[self.tableView_scrollShown reloadRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationTop];
}

- (void) tapGesturehandling: (UITapGestureRecognizer *) tap {
    
    if (tap.view.tag == 10) {
        
        ExchangeAndScoreHistoryController *shareVC = [[ExchangeAndScoreHistoryController alloc] init];
        [shareVC setType:@"scoreHistory"];
        
        [self.navigationController pushViewController:shareVC animated:YES];
    } else if (tap.view.tag == 11) {
        
        ExchangeAndScoreHistoryController *shareVC = [[ExchangeAndScoreHistoryController alloc] init];
        [shareVC setType:@"exchangeHistory"];
        
        [self.navigationController pushViewController:shareVC animated:YES];
    }
}

//签到跳转
- (void) signingRuleShown {
    
    [UsefulUtil showAlertView:@"这儿会链接一个H5网页来显示"];
    NSLog(@"签到的H5");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
    NSLog(@"兑换页面出了内存问题");
    [self.timer invalidate];
}
@end
